package com.example.flower_shop.dto.cart;

import com.example.flower_shop.dto.product.ProductVO;
import com.example.flower_shop.entity.CartItem;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class CartItemVO {
    private Long id;
    private ProductVO product;
    private Integer quantity;
    private Boolean isAvailable; // 商品是否可购买（库存充足且上架）

    public CartItemVO(CartItem cartItem) {
        this.id = cartItem.getId();
        this.product = new ProductVO(cartItem.getProduct());
        this.quantity = cartItem.getQuantity();
        this.isAvailable = cartItem.getProduct().getStatus() == 1 &&
                cartItem.getProduct().getStock() >= cartItem.getQuantity();
    }
}